package ru.acme.lab08.task6;

import java.util.Scanner;
import java.io.File;
import java.io.FileNotFoundException;

class Task6 {
	private static final int NOT_COMMENT_STATE = 0;
	private static final int MANY_LINES_COMMENT_STATE = 1;
	private static final int ONE_LINE_COMMENT_STATE = 2;
	private static final int TWO_QUOTES_LITERAL_STATE = 3;
	private static final int ONE_QUOTE_LITERAL_STATE = 4;
	
	public static void main(String[] argv) {
		if (argv.length < 1) {
			System.out.println("File name argument is needed");
			return;
		}
		Integer state = 0;
		Scanner fileScanner;
		try {
			fileScanner = new Scanner(new File(argv[0]));
		} catch (FileNotFoundException e) {
			e.printStackTrace();
			return;
		}
		while(fileScanner.hasNext()) {
			String line = fileScanner.nextLine();
			String processedLine = "";
			for (int i = 0; i < line.length(); ++i) {
				switch (state) {
					case NOT_COMMENT_STATE:
						if ((line.charAt(i) == '/') && (i < line.length() - 1)) {
							if (line.charAt(i + 1) == '/') {
								state = ONE_LINE_COMMENT_STATE;
								++i;
							} else if (line.charAt(i + 1) == '*') {
								state = MANY_LINES_COMMENT_STATE;
								++i;
							} else {
								processedLine += line.charAt(i);
							}
						} else {
							if (line.charAt(i) == '"') {
								state = TWO_QUOTES_LITERAL_STATE;
							}
							if (line.charAt(i) == '\'') {
								state = ONE_QUOTE_LITERAL_STATE;
							}
							processedLine += line.charAt(i);				
						}
						break;
					case MANY_LINES_COMMENT_STATE:
						if ((line.charAt(i) == '*') && (i < line.length() - 1) && (line.charAt(i + 1) == '/')) {
							state = NOT_COMMENT_STATE;
							++i;
						}
						break;
					case TWO_QUOTES_LITERAL_STATE:
						if (line.charAt(i) == '"') {
							state = NOT_COMMENT_STATE;
						}
						processedLine += line.charAt(i);				
						break;
					case ONE_QUOTE_LITERAL_STATE:
						if (line.charAt(i) == '\'') {
							state = NOT_COMMENT_STATE;
						}
						processedLine += line.charAt(i);				
						break;
				}
			}
			if (processedLine.length() > 0) {
				System.out.println(processedLine);
			}
			if (state == 2) {
				state = 0;
			}
		}
		fileScanner.close();	
	}
}